<?php
class Blog extends Controller
{
	function Blog()
	{
		parent::Controller();		
		$this->load->library('simplepie');
		$this->load->helper('html');
		$this->load->helper('url');
		$this->load->helper('mypage'); //zeratool helper.
		$this->load->helper('request');
	}
	
	function index()
	{		
		$data['title'] = "Blog";
		$data['blog_items'] = $this->getBlog();
		
		$request = getRequests();
		
		if ($request['article'] == 'zero')
		{
			$data['article'] = 0;
		}
		else
		{
			$data['article'] = $request['article'];
		}
		$data['latestten'] = $this->latestTen();
		$this->load->view('blog', $data);
	}
	
	function getBlog (){
		$this->load->library('simplepie');
		$this->simplepie->set_feed_url('http://badjography.blogspot.com/feeds/posts/default');
		$this->simplepie->set_cache_location(APPPATH.'cache/rss');
		$this->simplepie->init();
		$this->simplepie->handle_content_type();
 
		return $this->simplepie->get_items();
	}
	
	function latestTen()
	{
		$theblog = $this->getBlog();
		$totalblog = count($theblog);
		$titles = "";
		
		if ($totalblog > 10)
		{
			$netblog = 10;
		}
		else
		{
			$netblog = $totalblog;
		}
		
		for($x=0;$x<$netblog;$x++)
		{
			if ($x == 0)
			{
				$request_data = 'zero';
			}
			else
			{
				$request_data = $x;
			}
			
			/*
			 * clean titles 20091006
			 */
			$stripquote = str_replace("'","", $theblog[$x]->get_title());
			$stripspace = str_replace(" ","-", $stripquote);
			$tolower = strtolower($stripspace);
			/*
			 * end clean titles
			 */
			
			$title = "<a href=\"".base_url()."blog/index/article:".$request_data."/".$tolower."\">".$theblog[$x]->get_title()."</a>";
			$titles .= $title . "<br>";
		}
		
		return $titles;
	}
}

/* End of file blog.php */
/* Location: ./system/application/badjography/controllers/blog.php */
